package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxx.server.mapper.TleaveMapper;
import com.xxxx.server.pojo.Admin;
import com.xxxx.server.pojo.RespPageBean;
import com.xxxx.server.pojo.Tleave;
import com.xxxx.server.service.ITleaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 教职工离校报备 服务实现类
 * </p>
 *
 * @author zhoubin
 * @since 2022-06-02
 */
@Service
public class TleaveServiceImpl extends ServiceImpl<TleaveMapper, Tleave> implements ITleaveService {

    @Autowired
    private TleaveMapper tleaveMapper;

    @Override
    public List<Tleave> getTleaveByTlId() {
        return tleaveMapper.getTleaveByTlId(((Admin) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId());
    }

    @Override
    public RespPageBean getTealeaveByPage(Integer currentPage, Integer size, Tleave tleave, String[] beginDateScope) {
        //开启分页
        Page<Tleave> page = new Page<>(currentPage,size);
        IPage<Tleave> tleaveByPage = tleaveMapper.getTealeaveByPage(page, tleave, beginDateScope);
        RespPageBean respPageBean = new RespPageBean(tleaveByPage.getTotal(), tleaveByPage.getRecords());
        return respPageBean;

    }

    @Override
    public List<Tleave> getTleave(Integer id) {
        return tleaveMapper.getTleave(id);
    }
}
